package cc.atliberty.oa.service.impl;

import cc.atliberty.oa.mapper.EmployeeMapper;
import cc.atliberty.oa.pojo.Employee;
import cc.atliberty.oa.pojo.EmployeeVo;
import cc.atliberty.oa.service.EmployeeService;
import cc.atliberty.oa.utils.DataGridView;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("EmployeeService")
public class EmployeeImpl implements EmployeeService {
    
    @Autowired
    private EmployeeMapper employeeMapper;
    
    @Override
    public DataGridView queryAllEmployee(EmployeeVo employeeVo) {

        Page<Object> page = PageHelper.startPage(employeeVo.getPage(), employeeVo.getLimit());
        List<Employee> data = employeeMapper.queryAllEmployee(employeeVo);
        return new DataGridView(page.getTotal(), data);
    }

    @Override
    public void addEmployee(EmployeeVo employeeVo) {
        employeeMapper.insertSelective(employeeVo);
    }

    @Override
    public void deleteEmployee(String identity) {
        employeeMapper.deleteEmployeeById(identity);
    }

    @Override
    public void updateEmployee(EmployeeVo employeeVo) {
        employeeMapper.updateEmployee(employeeVo);
    }

    @Override
    public void deleteBatchEmployee(String[] ids) {
        for (String identity : ids){
            this.deleteEmployee(identity);
        }
    }
}
